Questions
19 of 25
1How do you build a reusable pagination and sorting query DTO that can be extended by feature-specific DTOs in NestJS?
2How do you use ClassSerializerInterceptor with @Exclude() and @Expose() to control response shape in NestJS?
3What versioning strategies does NestJS support and how do you enable versioning?
4How do you implement idempotency keys for POST requests to prevent duplicate operations in NestJS?
5How do you implement API rate limiting per user or per IP in NestJS?
6How do you handle raw body access for webhook signature verification in NestJS?
7How do you stream a large file or dataset as a response without loading it fully into memory in NestJS?
8How do you implement content negotiation so an endpoint returns JSON or CSV based on the Accept header in NestJS?
9How do you set a default version so unversioned requests are handled by a specific version in NestJS?
10How do you document DTO properties for Swagger and handle optional vs required fields in NestJS?
11How do you handle HATEOAS hypermedia links in NestJS REST responses?
12What decorators does NestJS provide for route parameters and how do they differ from query params?
13How do you handle a route where the param can be either a numeric ID or the literal string 'me' in NestJS?
14How do you handle multi-value query parameters (arrays) in NestJS?
15What is the difference between @Body(), @Body('field'), and using a full DTO class in NestJS?
16How do you implement a PATCH endpoint correctly with partial validation using PartialType in NestJS?
17How do you implement discriminated union body validation where the DTO shape depends on a type field in NestJS?
18How do you set HTTP status codes, response headers, and redirects in NestJS without using @Res()?
19What is the recommended file structure for versioned controllers in a NestJS project?
20How do wildcard and optional route segments work in NestJS?
21What is the difference between @Param('id') and @Param() with no argument in NestJS?
22How do you extract and type query parameters in NestJS including optional ones with defaults?
23How do you implement a standard paginated response envelope across all list endpoints in NestJS?
24How do you apply versioning at controller and method level in NestJS and how do you mark a route as version-neutral?
25How do you set up Swagger in a NestJS application and annotate your controllers?
19 / 25

What is the recommended file structure for versioned controllers in a NestJS project?

Organize versioned controllers into subdirectories (v1/, v2/) within each feature module folder. The feature module imports both controller classes. Shared DTOs live in a dto/ subdirectory outside the version folders. For small APIs, version-specific logic can live in service methods instead of separate service classes.

Versioned controller folder layout
Versioned project structure guidelines:
  1. 1

    v1/ and v2/ subdirectories keep version-specific code isolated and independently testable.

  2. 2

    Shared DTOs go in a common dto/ folder — versioning only applies to the request/response layer.

  3. 3

    For large teams, separate service classes per version prevent one version's changes from breaking another.

  4. 4

    For small APIs, a single service with version-branching logic is acceptable to avoid code duplication.

  5. 5

    The module registers all controller versions — clients route to the right one via the versioning strategy.

Difficulty: 5/10
Topics: file organization, API versioning, module structure

Scenario Questions

0-2 years experience
  1. 1

    We need to add a v2 of the Users API to a small NestJS project that currently only has v1. How would you lay out the controller files and modules?

  2. 2

    If you placed the v2 UsersController in the same folder as the v1 controller, what issues could arise during routing or testing?

2-5 years experience
  1. 1

    During a sprint, a teammate added a new endpoint to the v2 OrdersController but accidentally imported it into the v1 OrdersModule, causing a 404 at runtime. How would you locate and fix the problem?

  2. 2

    We have a feature that must be released to v2 first, then rolled back to v1 if needed. Explain how you would structure the files and versioning configuration to support this workflow.

5-8 years experience
  1. 1

    Our monorepo now contains ten versioned modules (v1‑v10) with many shared services. Discuss the trade‑offs between a flat version folder (src/v1, src/v2, …) versus a nested per‑feature structure (src/users/v1, src/users/v2). Consider build time, test isolation, and developer onboarding.

  2. 2

    You need to share validation logic across all versions without duplicating code. How would you organize the file hierarchy and Nest modules to keep versioned controllers separate but still reuse common utilities?

8+ years experience
  1. 1

    The organization is moving from a custom versioning approach to NestJS's built‑in versioning across dozens of microservices. What architectural changes to the file structure would you recommend to minimize disruption and make future version increments painless?

  2. 2

    Design a versioned controller strategy that can comfortably scale to 15+ API versions while allowing new teams to add their own versioned features without deep knowledge of existing layout. What conventions and folder patterns would you enforce?

Follow-up Questions

  • How does NestJS decide which controller handles a request when multiple versions exist?
  • What steps would you take to deprecate a v1 endpoint while keeping the codebase clean?